package com.kinon.bs_app.activities;

import android.content.Intent;
import android.os.Handler;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;

import com.kinon.bs_app.R;
import com.kinon.bs_app.constants.Constants;
import com.kinon.bs_app.utils.BaseActivity;

public class SplashActivity extends BaseActivity {

    private AlphaAnimation animation = null;

    private Button btn_skip = null;

    private Handler mHandler = new Handler();

    private Runnable mRunnable = new Runnable() {
        @Override
        public void run() {
            gotoLoginActivity();
        }
    };

    private TranslateAnimation translateAnimation = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initView();
//        initAnimation();  // 若skip后无法关闭则 获取2次token
    }

    private void initView() {
        btn_skip = findViewById(R.id.btn_skip);
        mHandler.postDelayed(mRunnable, Constants.SKIP_TIME);
        btn_skip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                gotoLoginActivity();
            }
        });
    }

    private void initAnimation() {
        animation = new AlphaAnimation(0.1f, 1.0f);
        animation.setDuration(1500);
        btn_skip.startAnimation(animation);
    }

    private void gotoLoginActivity() {
        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacks(mRunnable);
    }
}
